package com.bee.user.service.impl;

import com.bee.commons.utils.UuidUtil;
import com.bee.user.mapper.RoleMapper;
import com.bee.user.mapper.UserMapper;
import com.bee.user.common.domain.UserDO;
import com.bee.user.common.vo.UserVO;
import com.bee.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Damin.yang
 * @date 2019/08/17 17:23
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public UserVO queryById(Long userId) {
        UserDO userDO = userMapper.selectById(userId);
        return UserVO.convert(userDO);
    }

    @Override
    public boolean createUser(UserDO domain) {
        domain.setSalt(UuidUtil.getUuid());
        domain.setPassword(null);
        domain.setEnable(Boolean.TRUE);
        userMapper.insert(domain);
        return true;
    }

    @Override
    public UserDO queryUser(String uname) {
        return userMapper.queryByUsernameOrPhone(uname);
    }

    @Override
    public List<String> getUserRoles(Long userId) {
        return roleMapper.queryUserRole(userId);
    }
}
